<?php
include 'connect_db.php';
if (!checkLoggedin())
{
  header('Location: login.php');
}

if(isset($_GET['id']))
{
  $house_id = $_GET['id'];
  $query = "SELECT * FROM houses
            WHERE houses.id = " . $house_id;
  $house = mysql_fetch_array(mysql_query($query));

  if(!isset($house['id']))
    header('Location: index.php');
}
else
{
  header('Location: index.php');
}


?>

<?php include('templates/main/header.php'); ?>

<div id="body">
  <div id="content" class="right_sidebar">
	<div id="invite">
		<hr>
		<h1>Invite a Friend</h1>
		<hr>
		<br />
		<br />
		<div id="houses" class="invite">
		<?php
			echo '<h2 class="house-name">'.$house['name'].'</h2>';
			echo		'<p id="address" class="address">'.$house['address'].'</p>';
		?>
		<div id="map_canvas" class="map_canvas" ></div>
		</div>
	
		<form name="input" action="invite_2.php" method="POST">
			<label>
				Email*:<span class="error"></span>
				<input name="email" value="" type="text">
			</label>

			<label>
				Message:<span class="error"></span>
				<textarea name="message" cols="90" rows="9" >Hi! I'd like to invite you to my house!</textarea>
			</label>

			<input name="house_id" value="<?php echo $_GET['id']; ?>" type="hidden">
			<input name="house_name" value="<?php echo $house['name']; ?>" type="hidden">
			<input name="lastname" value="<?php echo $_SESSION['lastname']; ?>" type="hidden">
			<input name="firstname" value="<?php echo $_SESSION['firstname']; ?>" type="hidden">

			<input type="submit" value="Send" name="submit">
		</form>
	</div>
  </div>
</div>
 
	<script>
	var address = document.getElementById('address').innerHTML;
	var geocoder;
	var map;

	geocoder = new google.maps.Geocoder();
	var latlng = new google.maps.LatLng(-34.397, 150.644);
	var mapOptions = 
	{
	  zoom: 18,
	  mapTypeId: 'satellite'
	}
	map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
	
	geocoder.geocode({ 'address': address},
	  function(results, status)
	  {
		if (status == google.maps.GeocoderStatus.OK)
		{
		  map.setCenter(results[0].geometry.location);
		}
		else
		{
		  alert('Geocode was not successful for the following reason: ' + status);
		}
	  });

	 var contentString =
		  '<h4>'+'Sharp 101'+'</h4>';//add pop-up window content
	  var infowindow = new google.maps.InfoWindow({
		  content: contentString//create pop-up window
	  });

	  map.setTilt(45);
	</script>
 
<?php include('templates/main/footer.php'); ?>